<template>
	<view>
		
		<inputs :titleWidth="140" class="whiteBg" title="排放依据" name="basis" v-model="emissionReference"></inputs>
		
		<b-maker v-model="factorList" class="pt10">
			
			<b-clone v-for="( item , index) in factorList" :key="index">
				
				<view class="whiteBg bt">
					<inps :titleWidth="140" title="污染因子" name="factor" v-model="item.factor" :list="factors" :multi="false" placeholder="请输入主要污染因子"></inps>
					<inputs :titleWidth="140" title="上限值" name="max" v-model="item.max"></inputs>
					<inputs :titleWidth="140" title="下限值" name="min" v-model="item.min"></inputs>
				</view>
				
			</b-clone>
			
		</b-maker>
		
		<!-- {{factorList}} -->
		
		<view style="height: 160rpx;"></view>
		
		<view class="plr fixed bottom ptb10 whiteBg">
			<view class="safeBottom">
				<button @tap="confirm" class="btn block rds23 shadow">确认</button>
			</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				type : '' ,
				emissionReference : '' ,
				factorList : [{}]
			}
		},
		computed:{
			isWater(){
				return this.type && (this.type.indexOf("废水") > -1 || this.type.indexOf("清下水") > -1 );
			},
			
			isGas(){
				return this.type && ( this.type.indexOf("废气") > -1 || this.type.indexOf("VOCS") > -1 );
			},
			factors(){
				let waters = ["COD", "PH", "总磷", "总氮", "氨氮"];
				let gas = ["二氧化硫", "氮氧化物", "颗粒物", "非甲烷总烃", "氯化氢", "氟化物", "一氧化碳"] ;
				if (!this.type) {
					return [ ...waters , ...gas ] ;
				}
				if (this.isWater) {
					return waters ;
				}
				if (this.isGas) {
					return gas ;
				}
				return [ ...waters , ...gas ] ;
			}
		},
		onLoad(p) {
			this.type = p.type ;
			this.emissionReference = p.emissionReference ;
			this.factorList = p.factorList ? JSON.parse(p.factorList) : [{}] ;
		},
		methods: {
			isNull(maybeNull) {
				return maybeNull === undefined || maybeNull === "" || maybeNull === null || maybeNull === NaN ;
			},
			confirm(){
				uni.$emit("saveFactors" ,{
					refers : this.emissionReference ,
					factorList : this.getFactorList()
				});
				uni.navigateBack({
					delta:1
				});
			},
			getFactorList(){
				let list = this.factorList.filter(c=> !(this.isNull(c.factor) && this.isNull(c.min) && this.isNull(c.max)) ) ;
				return JSON.stringify(list) ;
			}
		}
	}
</script>
<style>
	page{
		background-color: #fff;
	}
</style>